// curriculum//pages/course_tv/index.js
const api = require('../../../utils/api').apis;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    Classification:'',
    type:'mini',
    src:'',
    net:false,
    userType:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var Xd_Token = wx.getStorageSync('Xd_Token')
    var id = options.id
    var userInfo = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo'):''
    this.setData({
      userType:userInfo.userType ?userInfo.userType: 'user'
    })
    var _this = this
    wx.getNetworkType({
      success(res){
        var net = wx.getStorageSync('net') ? wx.getStorageSync('net'): false
        console.log(res.networkType)
        if(res.networkType == 'wifi' || net){
          var net = true
        } else{
          var net = false
        }
        _this.setData({
          net:net
        })
      }

    })
    
    wx.showLoading({
      title: '加载中',
    })
    api.searchCourseMessage({
      id:id,
      pageSize:""
    }).then(res=>{
      console.log(res.data.curriculum.curriculumForm)
      // if(res.data.curriculum.curriculumForm == "offline"){
      //   wx.navigateTo({
      //     url: '/curriculum/pages/course/index?id='+res.data.curriculum.id,
      //   })
      // }else{
        let userTypes=userInfo.userType ?userInfo.userType: 'user'
        let userNumber = wx.getStorageSync('userNumber') ? wx.getStorageSync('userNumber') :''

      this.setData({
        Classification:res.data.curriculum.curriculumForm,
      })
      var src = "https://xdtest.wisewin-tech.com/miniVideo?id="+this.data.id+"&type="+this.data.type+"&classification="+this.data.Classification+'&token='+Xd_Token+'&net='+this.data.net+'&usertype='+userTypes+'&usernuber='+userNumber;
      // var src = "http://localhost:8083/miniVideo?id="+this.data.id+"&type="+this.data.type+"&classification="+this.data.Classification+'&token='+Xd_Token+'&net='+this.data.net+'&usertype='+userTypes+'&usernuber='+userNumber;
      this.setData({
        src:src
      })
      // }
      
      
      wx.hideLoading()
      console.log(src)
      console.log(res)
    })
    this.setData({
      id:id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})